package controller
{
	import away3d.entities.Mesh;
	import away3d.materials.ColorMaterial;
	import away3d.primitives.CubeGeometry;
	
	import controller.bullets.StraightBullet;
	
	import flash.events.TimerEvent;
	import flash.geom.Matrix3D;
	import flash.utils.Timer;
	
	import gameObject.GameObjectBase;
	import gameObject.SingleBullet;
	import gameObject.WeaponMain;
	import gameObject.resources3D.WeaponResource;
	
	import tool.FireTimer;

	public class MainWeaponController extends GameControllerBase
	{
		private var _weapon:WeaponMain;
		
		private var _fireTimer:FireTimer;
		private var _fireCount:uint=0;
		
		public function MainWeaponController(){}
		
		public function get fireTimer():FireTimer
		{
			return _fireTimer;
		}

		override public function setup(target:GameObjectBase):void
		{
			super.setup(target);
			
			_weapon = target as WeaponMain;
			_fireTimer = new FireTimer(1000/_weapon.speed,_weapon);
		}
		
		override public function dispose():void
		{
			_target.controller = null;
		}
		
		public function fire():void//发射一颗子弹
		{
			var bullet:SingleBullet = _weapon.newBullet();
			bullet.controller = new StraightBullet();
			
			var test:Mesh = new Mesh(new CubeGeometry(5,5,5),new ColorMaterial);
			
			//初始化子弹坐标
			var mainWep:WeaponMain = _target as WeaponMain;
			var wepRes:WeaponResource = mainWep.resource as WeaponResource;
			var trans:Matrix3D = wepRes.firePoint.sceneTransform;
			bullet.transform = trans;
			bullet.rotationX+=90;
			bullet.controller.instObj.transform = bullet.transform;
			
			Global.gameView.scene.addChild(bullet);
			bullet.addChild(test);
			
			bullet.controller.fire();
		}
	}
}